home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / game / think / AmiChess.lha / AmiChess / src / quiesce.c < prev    next >
C/C++ Source or Header  |  2002-10-31  |  1KB  |  60 lines

  1. #include "common.h"
  2.  
  3. int Quiesce(short ply,int alpha,int beta)
  4. {
  5. short side,xside;
  6. int best,delta,score,savealpha;
  7. leaf *p,*pbest;
  8. if(EvaluateDraw()) return DRAWSCORE;
  9. side=board.side;
  10. xside=1^side;
  11. InChk[ply]=SqAtakd(board.king[side],xside);
  12. best=Evaluate(alpha,beta);
  13. if(best>=beta&&!InChk[ply]) return best;
  14. TreePtr[ply+1]=TreePtr[ply];
  15. if(InChk[ply])
  16.     {
  17.     GenCheckEscapes(ply);
  18.     if(TreePtr[ply]==TreePtr[ply+1]) return -MATE+ply-2;
  19.     if(best>=beta) return best;
  20.     SortMoves(ply);
  21.     }
  22. else
  23.     {
  24.     GenCaptures(ply);
  25.     if(TreePtr[ply]==TreePtr[ply+1]) return best;
  26.     SortCaptures(ply);
  27.     }
  28.  
  29. savealpha=alpha;
  30. pbest=0;
  31. alpha=MAX(best,alpha);
  32. delta=MAX(alpha-150-best,0);
  33. for(p=TreePtr[ply];p<TreePtr[ply+1];p++)
  34.     {
  35.     pick(p,ply);
  36.     if(!InChk[ply]&&SwapOff(p->move)<delta) continue;
  37.     if(p->score==-INFINITY) continue;
  38.     MakeMove(side,&p->move);
  39.     QuiesCnt++;
  40.     if(SqAtakd(board.king[side],xside))
  41.         {
  42.         UnmakeMove(xside,&p->move);
  43.         continue;
  44.         }
  45.     score=-Quiesce(ply+1,-beta,-alpha);
  46.     UnmakeMove(xside,&p->move);
  47.     if(score>best)
  48.         {
  49.         best=score;
  50.         pbest=p;
  51.         if(best>=beta) goto done;
  52.         alpha=MAX(alpha,best);
  53.         }
  54.     }
  55.  
  56. done:
  57. if(flags&USEHASH&&pbest) TTPut(side,0,ply,savealpha,beta,best,pbest->move);
  58. return best;
  59. }
  60.